/**
 * Created by 林 on 2017/5/17 0017.
 */
var  panelCollapse1 = $('[data-panel="Collapse"]');
var  panelCollapse2 = $('[data-panel="Collapse"] .panel');
var  panelCollapse3 = $('[data-panel="Collapse"] .panel .list-group li');
panelCollapse2[0].index = false;
panelCollapse2.find('.panel-heading').click(function () {
    if( $(this).parent().get(0).index ){
        if( $(this).parent().hasClass('last-panel') ){
            $(this).parent().find('.list-group,.table-responsive,.table,.panel-body').slideDown(300)
                .parent().find('.panel-heading')
                .css({'border-bottom-left-radius':0,'border-bottom-right-radius':0});
            $(this).parent().get(0).index = false;
        }else{
            $(this).parent().find('.list-group,.table-responsive,.table,.panel-body').slideDown(300);
            $(this).parent().get(0).index = false;
        }
    }else{
        if( $(this).parent().hasClass('last-panel') ){
            $(this).parent().find('.list-group,.table-responsive,.table,.panel-body').slideUp(300)
                .parent().css({'overflow':'hidden'});
            $(this).parent().get(0).index = true;
        }else{
            $(this).parent().find('.list-group,.table-responsive,.table,.panel-body').slideUp(300);
            $(this).parent().get(0).index = true;
        }

    }

});

var scroll = $(window).scrollTop();
function pub(num1, num2) {
    panelCollapse1.css({'position':'fixed','top':0,'width':panelCollapse1.parent().width() + 'px'});
    panelCollapse2.find('.list-group,.table-responsive,.table,.panel-body').css('display','none');
    panelCollapse2.filter(':nth-child('+ num1 +')').find('.list-group,.table-responsive,.table,.panel-body').css('display','block');
    panelCollapse2.filter(':nth-child('+ num1 +')').get(0).index = false;

    panelCollapse3.css({'background':'#fff', 'color':'#555'});
    panelCollapse2.filter(':nth-child('+ num1 +')').find('.list-group li:nth-child('+ num2 +')').css({'background':'#5fb4c4', 'color':'#fff'});
}
if( scroll >= 350 && scroll < 3115 ){
    pub(1, 1);
}else if( scroll >= 3115 && scroll < 4100 ) {
    pub(1, 2);
}else if( scroll >= 4100 && scroll < 4500 ) {
    pub(1, 3);
}else if( scroll >= 4500 && scroll < 5020 ) {
    pub(2, 1);
}else if( scroll >= 5020 && scroll < 5320 ) {
    pub(2, 2);
}else if( scroll >= 5320 && scroll < 5865 ) {
    pub(2, 3);
}else if( scroll >= 5865 && scroll < 6460 ) {
    pub(2, 4);
}else if( scroll >= 6460 && scroll < 6940 ) {
    pub(2, 5);
}else if( scroll >= 6940 && scroll < 7385 ) {
    pub(3, 1);
}else if( scroll >= 7385 && scroll < 8085 ) {
    pub(3, 2);
}else if( scroll >= 8085 && scroll < 8585 ) {
    pub(3, 3);
}else if( scroll >= 8585 && scroll < 9285 ) {
    pub(4, 1);
}else if( scroll >= 9285 && scroll < 9585 ) {
    pub(4, 2);
}else if( scroll >= 9585 && scroll < 10050 ) {
    pub(4, 3);
}else if( scroll >= 10050 && scroll < 10350 ) {
    pub(4, 4);
}else if( scroll >= 10350 && scroll <= 10800 ) {
    pub(5, 1);
}else if( scroll >= 10800 && scroll <= 11565 ) {
    pub(5, 2);
}else if( scroll >= 11565 && scroll <= 12325 ) {
    pub(5, 3);
}else if( scroll >= 12325 && scroll <= 13025 ) {
    pub(6, 1);
}else if( scroll >= 13025 && scroll <= 13670 ) {
    pub(6, 2);
}else if( scroll >= 13670 && scroll <= 14200 ) {
    pub(6, 3);
}else if( scroll >= 14200 && scroll <= 14580 ) {
    pub(7, 1);
}else if( scroll >= 14580 && scroll <= 14865 ) {
    pub(7, 2);
}else if( scroll >= 14865 && scroll <= 15700 ) {
    pub(7, 3);
}else if( scroll >= 15700 && scroll <= 16500 ) {
    pub(7, 4);
}else if( scroll >= 16500 && scroll <= 17305 ) {
    pub(7, 5);
}else if( scroll >= 17305 && scroll <= 17705 ) {
    pub(7, 6);
}else if( scroll >= 17705 && scroll <= 18240 ) {
    pub(8, 1);
}else if( scroll >= 18240 && scroll <= 18750 ) {
    pub(8, 2);
}else if( scroll >= 18750 && scroll <= 19280 ) {
    pub(8, 3);
}else if( scroll >= 19280 && scroll <= 20050 ) {
    pub(8, 4);
}else if( scroll >= 20050 && scroll <= 21322 ) {
    pub(8, 5);
}else if( scroll >= 21322 && scroll <= 21622 ) {
    pub(9, 1);
}else if( scroll >= 21622 && scroll <= 22322 ) {
    pub(9, 2);
}else if( scroll >= 22322 && scroll <= 22722 ) {
    pub(9, 3);
}else if( scroll >= 22722 && scroll <= 23822 ) {
    pub(9, 4);
}else if( scroll >= 23822 && scroll <= 24422 ) {
    panelCollapse1.css({'position':'fixed','top':'-315px','width':panelCollapse1.parent().width() + 'px'});
    pub(9, 5);
}else if( scroll >= 24422 ) {
    panelCollapse1.css({'position':'fixed','top':'-315px','width':panelCollapse1.parent().width() + 'px'});
    pub(9, 6);

}else{
    panelCollapse1.removeAttr("style");
    panelCollapse3.css({'background':'#fff', 'color':'#555'});
}
function pubScroll(num1,num2,num3) {
    panelCollapse1.css({'position':'fixed','top':0,'width':panelCollapse1.parent().width() + 'px'});

    panelCollapse2.filter(':nth-child('+ num1 +')').find('.list-group,.table-responsive,.table,.panel-body').slideUp(300,function () {
        panelCollapse2.filter(':nth-child('+ num1 +')').find('.list-group,.table-responsive,.table,.panel-body').css('display','none');
        panelCollapse2.filter(':nth-child('+ num1 +')').get(0).index = true;
    });
    panelCollapse2.filter(':nth-child('+ num2 +')').find('.list-group,.table-responsive,.table,.panel-body').slideDown(300,function () {
        panelCollapse2.filter(':nth-child('+ num2 +')').find('.list-group,.table-responsive,.table,.panel-body').css('display','block');
        panelCollapse2.filter(':nth-child('+ num2 +')').get(0).index = false;

        panelCollapse3.css({'background':'#fff', 'color':'#555'});
        panelCollapse2.filter(':nth-child('+ num2 +')').find('.list-group li:nth-child('+ num3 +')').css({'background':'#5fb4c4', 'color':'#fff'});
    });
}
function pubChild(num1, num2) {
    panelCollapse1.css({'position':'fixed','top':0,'width':panelCollapse1.parent().width() + 'px'});
    panelCollapse2.filter(':nth-child('+ num1 +')').find('.list-group,.table-responsive,.table,.panel-body').css('display','block');
    panelCollapse2.not(':nth-child('+ num1 +')').find('.list-group,.table-responsive,.table,.panel-body').css('display','none');

    panelCollapse3.css({'background':'#fff', 'color':'#555'});
    panelCollapse2.filter(':nth-child('+ num1 +')').find('.list-group li:nth-child('+ num2 +')').css({'background':'#5fb4c4', 'color':'#fff'});
}
$(window).scroll(function () {
    var scroll = $(window).scrollTop();
    if( scroll >= 350 && scroll < 3115 ){
        pubScroll(2,1,1);
    }else if( scroll >= 3115 && scroll < 4100 ) {
        pubChild(1,2);
    }else if( scroll >= 4100 && scroll < 4500 ) {
        pubScroll(2,1,3);
    }else if( scroll >= 4500 && scroll < 5020 ) {
        pubScroll(1,2,1);
    }else if( scroll >= 5020 && scroll < 5320 ) {
        pubChild(2,2);
    }else if( scroll >= 5320 && scroll < 5865 ) {
        pubChild(2,3);
    }else if( scroll >= 5865 && scroll < 6460 ) {
        pubChild(2,4);
    }else if( scroll >= 6460 && scroll < 6940 ) {
        pubScroll(3,2,5);
    }else if( scroll >= 6940 && scroll < 7385 ) {
        pubScroll(2,3,1);
    }else if( scroll >= 7385 && scroll < 8085 ) {
        pubChild(3,2);
    }else if( scroll >= 8085 && scroll < 8585 ) {
        pubScroll(4,3,3);
    }else if( scroll >= 8585 && scroll <= 9285 ) {
        pubScroll(3,4,1);
    }else if( scroll >= 9285 && scroll <= 9585 ) {
        pubChild(4,2);
    }else if( scroll >= 9585 && scroll <= 10050 ) {
        pubChild(4,3);
    }else if( scroll >= 10050 && scroll <= 10350 ) {
        pubScroll(5,4,4);
    }else if( scroll >= 10350 && scroll <= 10800 ) {
        pubScroll(4,5,1);
    }else if( scroll >= 10800 && scroll <= 11565 ) {
        pubChild(5,2);
    }else if( scroll >= 11565 && scroll <= 12325 ) {
        pubScroll(6,5,3);
    }else if( scroll >= 12325 && scroll <= 13025 ) {
        pubScroll(5,6,1);
    }else if( scroll >= 13025 && scroll <= 13670 ) {
        pubChild(6,2);
    }else if( scroll >= 13670 && scroll <= 14200 ) {
        pubScroll(7,6,3);
    }else if( scroll >= 14200 && scroll <= 14580 ) {
        pubScroll(6,7,1);
    }else if( scroll >= 14580 && scroll <= 14865 ) {
        pubChild(7,2);
    }else if( scroll >= 14865 && scroll <= 15700 ) {
        pubChild(7,3);
    }else if( scroll >= 15700 && scroll <= 16500 ) {
        pubChild(7,4);
    }else if( scroll >= 16500 && scroll <= 17305 ) {
        pubChild(7,5);
    }else if( scroll >= 17305 && scroll <= 17705 ) {
        pubScroll(8,7,6);
    }else if( scroll >= 17705 && scroll <= 18240 ) {
        pubScroll(7,8,1);
    }else if( scroll >= 18240 && scroll <= 18750 ) {
        pubChild(8,2);
    }else if( scroll >= 18750 && scroll <= 19280 ) {
        pubChild(8,3);
    }else if( scroll >= 19280 && scroll <= 20050 ) {
        pubChild(8,4);
    }else if( scroll >= 20050 && scroll <= 21322 ) {
        pubScroll(9,8,5);
    }else if( scroll >= 21322 && scroll <= 21622 ) {
        pubScroll(8,9,1);
    }else if( scroll >= 21622 && scroll <= 22322 ) {
        pubChild(9,2);
    }else if( scroll >= 22322 && scroll <= 22722 ) {
        pubChild(9,3);
    }else if( scroll >= 22722 && scroll <= 23822 ) {
        pubChild(9,4);
    }else if( scroll >= 23822 && scroll <= 24422 ) {
        pubChild(9,5);
        panelCollapse1.css({'position':'fixed','top':'-315px','width':panelCollapse1.parent().width() + 'px'});
    }else if( scroll >= 24422 ) {
        pubChild(9,6);
        panelCollapse1.css({'position':'fixed','top':'-315px','width':panelCollapse1.parent().width() + 'px'});
    }else{
        panelCollapse1.removeAttr("style");
        panelCollapse2.filter(':nth-child(1)').find('.list-group,.table-responsive,.table,.panel-body').slideUp(300,function () {
            panelCollapse2.filter(':nth-child(1)').get(0).index = true;

            panelCollapse3.css({'background':'#fff', 'color':'#555'});
        });
    }

});